package com.endoc.enjoyplayer;

public class EnjoyPlayer {
    private final long nativeHandle;

    public EnjoyPlayer(){
        nativeHandle = init();
    }
    //初始化C++的EnjoyPlayer,因为返回的指针类型,所以用long接收就可以了
    public native long init();

    public void setDataSource(String path) {
        setDataSource(nativeHandle, path);
    }

    private native void setDataSource(long nativeHandle, String path);

    public void start() {

    }

    public void pause() {

    }

    public void stop() {

    }
    public native void nativePlay(String path);
    public native void nativePause();


    /**
     * 此方法是C层通过反射调用
     * @param errorCode
     */
    private void onError(int errorCode) {
        if (null != onErrorListener) {
            onErrorListener.onError(errorCode);
        }
    }

    /**
     * 此方法是C层通过反射调用
     */
    private void onPrepare() {
        if (null != onPrepareListener) {
            onPrepareListener.onPrepared();
        }
    }

    /**
     * 此方法是C层通过反射调用
     * @param progress 进度
     */
    private void onProgress(int progress) {
        if (null != onProgressListener) {
            onProgressListener.onProgress(progress);
        }
    }


    private OnErrorListener onErrorListener;
    private OnProgressListener onProgressListener;
    private OnPrepareListener onPrepareListener;


    public interface OnErrorListener {
        void onError(int err);
    }

    public interface OnPrepareListener {
        void onPrepared();
    }

    public interface OnProgressListener {
        void onProgress(int progress);
    }

}
